$(function () {
    // add listner to loginBtn
    $("#loginBtn").on("click", function () {
        // validate whether field is empty
        var validate = true;
        $("#loginForm").find("input").each(function () {
            if (!$(this).val()) {
                var prompt = $(this);
                prompt.popover('show');
                setTimeout(function () {
                    prompt.popover('hide');
                }, 3000);
                validate = false;
            }
        });
        // pass
        if (validate) {
            var formData = new FormData($("#loginForm").get(0));
            $.ajax({
                url: "/o2o-merchant/login.action",
                type: "post",
                data: formData,
                contentType: false,
                processData: false
            }).done(function (msg) {
                if (msg == "success") {
                    window.location.href = "/o2o-merchant/sec/home";
                } else {
                    $("#errorDiv").text("username or password wrong!");
                }
            });
        }
    });
    // add listener to registerBtn
    $("#registerBtn").on("click", function () {
        window.location.href = "/o2o-merchant/register";
    });
});